<style type="text/css">
    table td .checkbox label{padding-left: 25px}
    table td{vertical-align: top !important}
</style>
<br>
<br>
<br>
<div class="row">
    <div class="col-xs-12 col-md-12">
        <div class="grid simple">
            <div class="grid-body no-border">
                <form id="edit-goods-form" action="<?= DOMAIN.'goods/edit/'.$goods['goods_sn'] ?>" method="POST"> 
                    <input type="hidden" name="goods_sn" value="<?= $goods['goods_sn'] ?>" />
                    <div class="row">
                        <div class="row form-row">
                            <? for($i=1; $i<=$max_img; $i++): ?>
                                <?= goods_img($goods['goods_sn'], $i, 'medium')?>
                            <? endfor ?>
                        </div>
                        <br>
                        <br>

                        <h4>基本属性</h4>
                        <div class="row form-row">
                            <div class="col-xs-4 col-md-4">
                                <label class="form-label">名称 *</label>
                                <input type="text" value="<?= $goods['name'] ?>" name="name" class="form-control" placeholder="最少1个字最多20个字">
                            </div> 
                            <div class="col-xs-4 col-md-4">
                                <label class="form-label">英文名称 *</label>
                                <input type="text" value="<?= $goods['subname'] ?>" name="subname" class="form-control" placeholder="最少1个字最多20个字">
                            </div> 
                        </div>

                        <div class="row form-row">
                            <div class="col-xs-4 col-md-4">
                                <label class="form-label">类型 *</label>
                                <select name="type" class="select2 form-control">
                                    <? foreach($goods_type as $k=>$v): ?>
                                        <option value="<?= $k ?>" <?= ($goods['goods_type'] == $k ) ? 'selected="selected"' : "" ?>>
                                            <?= $v ?>
                                        </option>
                                    <? endforeach ?>
                                </select>
                            </div> 

                            <div class="col-xs-4 col-md-4">
                                <label class="form-label">价格</label>
                                <input type="text" value="<?= $goods['base_price'] ?>" name="base_price" class="form-control digits" placeholder="eg. 51.30">
                            </div> 
                            
                        </div>
                        <br>
                        <div class="row form-row">
                            <div class="col-xs-4 col-md-4">
                                <label class="form-label">分类 *</label>
                                <select name="category_id" class="select2 form-control">
                                    <? foreach($category as $cg): ?>
                                        <option value="<?= $cg['category_id'] ?>" <?= ($category_id == $cg['category_id'] ) ? 'selected="selected"' : "" ?>>
                                            <?= $cg['name'] ?>
                                        </option>
                                        <? if($cg['children']): ?>
                                            <? foreach($cg['children'] as $c): ?>
                                                <option value="<?= $c['category_id'] ?>" <?= ($category_id == $c['category_id'] ) ? 'selected="selected"' : "" ?>>
                                                  &nbsp;&nbsp;&nbsp;&nbsp;
                                                  <?= $c['name'] ?>
                                                </option>
                                            <? endforeach ?>
                                        <? endif ?>
                                    <? endforeach ?>
                                </select>
                            </div> 

                            <div class="col-xs-4 col-md-4">
                                <label class="form-label">品牌 *</label>
                                <select name="brand_sn" class="select2 form-control">
                                    <? foreach($brand as $b): ?>
                                        <option value="<?= $b['brand_sn'] ?>" <?= ($goods['brand_sn'] == $b['brand_sn'] ) ? 'selected="selected"' : "" ?>>
                                            <?= $b['name'] ?>
                                        </option>
                                    <? endforeach ?>
                                </select>
                            </div>
                        </div>
                        <br>
                        <br>

                        <h4>附加属性</h4>
                        <div class="row form-row">
                            <? if($attr): ?>
                            <table class="table">
                                <tbody>
                                <? foreach($attr as $a): ?>
                                <tr>
                                    <td>
                                        <strong><?= $a['name'] ?></strong>
                                    </td>
                                    <? if($a['children']): ?>
                                    <td>
                                        <? foreach($a['children'] as $av): ?>
                                            <div class="col-xs-2 col-md-2">
                                                <div class="checkbox check-success">
                                                    <input type="checkbox" id="attr-value-<?= $av['attr_value_id'] ?>"  name="attr_values[]" value="<?= $av['attr_value_id'] ?>" <? if( is_array($attr_value) && in_array($av['attr_value_id'], $attr_value)): ?>checked="checked"<? endif?>    >
                                                    <label for="attr-value-<?= $av['attr_value_id'] ?>"><?= $av['name'] ?></label>
                                                </div>
                                            </div>
                                        <? endforeach ?>
                                    </td>
                                    <? endif ?>
                                </tr>
                                <? endforeach ?>
                                </tbody>
                            </table>
                            <? endif ?>
                        </div>
                        <br>
                        <br>

                        <h4>详细介绍</h4>
                        <div class="row form-row">
                            <script id="desc" name="desc" type="text/plain"><?= $goods['desc'] ?></script>
                        </div>
                        <br>
                        <br>
                    </div>
                      
                    <div class="form-actions">  
                        <div class="pull-left">
                            <button class="btn btn-success btn-cons" type="submit">
                                <i class="icon-save"></i>&nbsp;保存</button>
                            </button>
                            <button class="btn btn-white btn-cons" type="button" onclick="$.T.reset_form(this)">
                                重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $('select[name="category_id"]').change(function(){
            $.ajax({
                url: $.G.domain+'goods/edit_temp',
                type: 'post',
                data: $('#edit-goods-form').serialize(),
                dateType: 'json',
                async:   false,
                success: function (response) 
                {
                    if(response.status == true)
                        $.T.refresh();
                }
            });
        });

        // 编辑器
        var ue = UM.getEditor('desc', {
            'initialFrameWidth' : 850,
        });
    });
</script>